using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using THSLib;
using THSERP.BusinessEntities;
namespace THSERP.BaseProvider
{
    public class ERPModuleItemsEntity : BusinessObject
    {
        public ERPModuleItemsEntity()
        {            
        }

        public virtual void GetFromBusinessObject(BusinessObject objBusinessObject)
        {
            PropertyInfo[] properties = objBusinessObject.GetType().GetProperties();
            foreach (PropertyInfo prop in properties)
            {
                PropertyInfo propModuleItemEntity = this.GetType().GetProperty(prop.Name);
                if (propModuleItemEntity != null)
                {
                    object objValue = prop.GetValue(objBusinessObject, null);
                    propModuleItemEntity.SetValue(this, objValue, null);
                }
            }
        }

        public BusinessObject SetToBusinessObject(String strBusinessObjectName)
        {
            BusinessObject objBusinessObject = BusinessObjectFactory.GetBusinessObject(strBusinessObjectName+"Info");
            PropertyInfo[] properties = objBusinessObject.GetType().GetProperties();
            foreach (PropertyInfo prop in properties)
            {
                PropertyInfo propModuleItemEntity = this.GetType().GetProperty(prop.Name);
                if (propModuleItemEntity != null)
                {
                    object objValue = propModuleItemEntity.GetValue(this, null);
                    prop.SetValue(objBusinessObject, objValue, null);
                }
            }

            return objBusinessObject;
        }
        
    }
}
